local extension = Package:new("zyg_espionage_cards", Package.CardPack)
extension.extensionName = "zzz_zyg_cards"
local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["zyg_espionage_cards"] = "用间Gamma（未完成）",
  }

local PresentCards = {}
local function addPreasentCard(c)
  extension:addCard(c)
  table.insert(PresentCards, c)
end


addPreasentCard(Fk:cloneCard("slash", Card.Heart, 5))
addPreasentCard(Fk:cloneCard("women_dress", Card.Heart, 5))
addPreasentCard(Fk:cloneCard("women_dress", Card.Heart, 5))
addPreasentCard(Fk:cloneCard("women_dress", Card.Heart, 5))
addPreasentCard(Fk:cloneCard("women_dress", Card.Heart, 5))
addPreasentCard(Fk:cloneCard("women_dress", Card.Heart, 5))
addPreasentCard(Fk:cloneCard("women_dress", Card.Heart, 5))
addPreasentCard(Fk:cloneCard("women_dress", Card.Heart, 5))
addPreasentCard(Fk:cloneCard("women_dress", Card.Heart, 5))
addPreasentCard(Fk:cloneCard("women_dress", Card.Heart, 5))
addPreasentCard(Fk:cloneCard("women_dress", Card.Heart, 5))
addPreasentCard(Fk:cloneCard("women_dress", Card.Heart, 5))

local present_skill = fk.CreateActiveSkill{
  name = "zyg__present_skill&",
  prompt = "#zyg__present_skill&",
  anim_type = "support",
  card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return table.find(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@zyg__present") > 0 end)
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select):getMark("@@zyg__present") > 0 and table.contains(Self:getCardIds("h"), to_select)
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    U.presentCard(player, target, Fk:getCardById(effect.cards[1]))
  end,
}
local espionage_rule = fk.CreateTriggerSkill{
  name = "#zyg_espionage_rule",
  priority = 0.001,
  global = true,
  refresh_events = {fk.GamePrepared},
  can_refresh = function(self, event, target, player, data)
    return not table.contains(player.room.disabled_packs, "zyg_espionage_cards")
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room.alive_players) do
      room:handleAddLoseSkills(p, "zyg__present_skill&", nil, false, true)
    end
    for _, card in ipairs(Fk.packages["zyg_espionage_cards"].cards) do
      if table.contains(PresentCards, card) then
        room:setCardMark(card, "@@zyg__present", 1)
      end
    end
  end,
}
Fk:addSkill(present_skill)
Fk:addSkill(espionage_rule)
Fk:loadTranslationTable{
  ["zyg__present_skill&"] = "赠予",
  [":zyg__present_skill&"] = "出牌阶段，你可以从手牌中将一张有“赠”标记的牌正面向上赠予其他角色。若此牌不是装备牌，则进入该角色手牌区；若此牌是装备牌，"..
  "则进入该角色装备区且替换已有装备。",
  ["#zyg__present_skill&"] = "将一张有“赠”标记的牌赠予其他角色",
  ["@@zyg__present"] = "<font color='yellow'>赠</font>",
}

return extension